const fetch = require('../../utils/util.js');
const query = fetch.fetch;
const api = fetch.api;
const formatTime = fetch.formatTime 

Component({
  behaviors: [],

  properties: {
    //已完成提示
    endMsgShow: { // 属性名
      type: Boolean, // 类型（必填），目前接受的类型包括：String, Number, Boolean, Object, Array, null（表示任意类型）
      value: false, // 属性初始值（可选），如果未指定则会根据类型选择一个
    },
    //出发按钮
    starBtnShow: { 
      type: Boolean, 
      value: true,
    },
    //出行状态码
    orderStatus:{
      type: Number,
      value:1,
    }
  },
  data:{
    //弹窗
    dialog:false,
    //数据
    dataMsg:[],
    inx:0
  },
  ready:function(){
      wx.getStorage({
        key: 'openid',
        success:  (res)=> {
          const data = query(api.gettobedone, 'post', { openId: res.data, orderStatus:this.data.orderStatus});
          data.then(data=>{
           for (let a of data){
             a.startDate = formatTime(a.startDate)
           }
            this.setData({
              dataMsg: data
            })  
            
          })
          
        }
      }) 
  },
  methods: {
   
    showDia(e){
      let id=e.currentTarget.id
      this.setData({
        dialog:true,
        inx:id 
      })
    },
    closeDia(){
      this.setData({
        dialog: false
      })
    },
    bindInput(e) {
      this.setData({
        value: e.detail.value
      })
    },
    sendMag(){
      wx.getStorage({
        key: 'openid',
        success: (res) => {
          const data = query(api.sendtobedone, 'post', { openId: res.data, travelNo: this.data.dataMsg[this.data.inx].travelNo, startKm:this.data.value });
          data.then(data => {
            if(data==1){
              this.closeDia();
              wx.switchTab({
                url: '../travel/travel'
              })
            } else if(data==2){
              wx.showLoading({
                title: '正在行驶中',
              })
              setTimeout(function () {
                wx.hideLoading()
              }, 1000)
            }
          })
        }
      }) 
      
    },
    
  }

})